//
//  YTHDCommentCell.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/18.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "YTHDCommentCell.h"
@interface YTHDCommentCell ()
@property (weak, nonatomic) IBOutlet UILabel *timeLabel;
@property (weak, nonatomic) IBOutlet UILabel *authorLabel;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *contentLabel;
@property (weak, nonatomic) IBOutlet UIButton *likeButton;

@end
@implementation YTHDCommentCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setCommentModel:(YTHDComment *)commentModel
{
    _commentModel = commentModel;
    
    self.authorLabel.text = commentModel.display_name;
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:commentModel.user_avatar]];
    self.timeLabel.text = commentModel.comment_date;
    self.contentLabel.text = commentModel.comment_content;
    self.likeButton.selected = commentModel.isrecommend.boolValue;
    [self.likeButton setTitle:commentModel.recommend_add forState:UIControlStateNormal];
    [self.likeButton setTitle:commentModel.recommend_add forState:UIControlStateSelected];
}

- (IBAction)likeButtonClick:(UIButton *)sender
{
    // 没登陆
    if (!YTNetworkManager.shareManager.account.auth) {
        [NSNotificationCenter.defaultCenter postNotificationName:kShouldLoginNotication object:nil];
        return;
    }
    
    [YTNetworkManager.shareManager requestDetailLikeCommentWithTid:self.tid pid:self.commentModel.comment_ID completion:^(BOOL isSucc, NSString *error)
    {
        if (!isSucc) {
            [self showTipWithTipStr:error];
            return ;
        }
        
        [self showAwardWithTipStr:error];
        
        sender.selected = YES;
        [sender setTitle:[NSString stringWithFormat:@"%d",(self.commentModel.recommend_add.intValue + 1)] forState:UIControlStateNormal];
        [sender setTitle:[NSString stringWithFormat:@"%d",(self.commentModel.recommend_add.intValue + 1)] forState:UIControlStateSelected];
    }];
}

@end
